package com.geetour.columbus.admin.dao.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.geetour.columbus.admin.dao.IAdminDAO;
import com.geetour.columbus.common.model.A.Admin;
import com.geetour.columbus.common.utils.DateUtils;
import com.geetour.columbus.core.ibatis.SqlMapClientDaoSupportEx;
import com.ibm.icu.util.Calendar;

@Service
public class AdminDAOImpl extends SqlMapClientDaoSupportEx implements IAdminDAO {

    @SuppressWarnings("unchecked")
    @Override
    public List<Admin> getAdmins(Admin admin) {
        if (admin == null) {
            return null;
        }
        return (List<Admin>) this.queryList("findAdmins", admin);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Admin> getAllAdmins() {
        return (List<Admin>) this.queryList("findAllAdmins", null);
    }

    @Override
    public int updateAdmin(Admin admin) {
        if (admin == null) {
            return -1;
        }
        return this.update("updateAdmin", admin);
    }

    @Override
    public int updateModifydate(String uuid) {
        if (uuid == null) {
            return -1;
        }
        Admin admin = new Admin();
        admin.setUuid(uuid);
        admin.setModifydate(DateUtils.formatDate(Calendar.getInstance().getTime(), DateUtils.format));
        return this.update("updateModifydate", admin);
    }

    @Override
    public int deleteAdminById(Long id) {
        if (id == null) {
            return -1;
        }
        return this.delete("deleteAdminById", id);
    }

    @Override
    public int deleteAdminByUuid(String uuid) {
        if (uuid == null) {
            return -1;
        }
        return this.delete("deleteAdminByUuid", uuid);
    }

    @Override
    public int insertAdmin(Admin admin) {
        if (admin == null) {
            return -1;
        }
        this.insert("insertAdmin", admin);
        return 1;
    }

}
